package com.dao.userdao;

import com.mapper.UserMapper;
import com.pojo.User;
import com.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;

public class Login {
     /***
      * 验证账号密码是否正确
      */
         public static boolean login_check(User user) throws IOException {
              boolean resp=true;
             //获取sqlSession对象
             SqlSession sqlSession= MybatisUtil.getSqlSession();
             //3.获取Mapper接口的代理对象
             UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
             //4.执行方法
             User user1=userMapper.login_check(user);
             //提交事务
             sqlSession.commit();
             //5.释放资源
             sqlSession.close();

             if(user1==null){
                 resp=false;
             }else{
                 resp=true;
             }
              return resp;
         }

    /**
     * 管理员登录验证
     */
      public static boolean manager_login(String username,String pwd)throws IOException{
          boolean resp=true;
          //获取sqlSession对象
          SqlSession sqlSession= MybatisUtil.getSqlSession();
          //3.获取Mapper接口的代理对象
          UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
          //4.执行方法
          int id=userMapper.manager_login(username,pwd);
          String id_str=id+"";
          //提交事务
          sqlSession.commit();
          //5.释放资源
          sqlSession.close();

          if("".equals(id_str)){
              resp=false;
          }else{
               resp=true;
          }
          return resp;
      }
}
